package msrc

import (
	"net/http"
	"testing"
	"time"
)

func TestFunctional(t *testing.T) {
	service := MultiService(map[string]ServiceInterface{
		"Test": HttpServerMock("45000"),
	}, 39100)

	go func() {
		_ = service.Run()
	}()

	defer service.Stop()

	time.Sleep(100 * time.Millisecond)

	aliveResp, err := http.Get("http://localhost:39100/alive")
	if nil != err {
		t.Fatalf(`/alive error=%v, want=nil`, err)
	}

	if aliveResp.StatusCode != http.StatusOK {
		t.Fatalf(`/alive status=%v, want=%v`, aliveResp.StatusCode, http.StatusOK)
	}

	testResp, err := http.Get("http://localhost:45000/test")
	if nil != err {
		t.Fatalf(`/test error=%v, want=nil`, err)
	}

	if testResp.StatusCode != http.StatusAccepted {
		t.Fatalf(`/test status=%v, want=%v`, testResp.StatusCode, http.StatusAccepted)
	}
}
